package com.irdstudio.bsp.console.api.rest;

import com.irdstudio.bsp.console.service.vo.HomePageVO;
import com.irdstudio.bsp.console.service.facade.HomePageService;
import com.irdstudio.bsp.console.service.vo.SSubsInfoVO;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.ssm.web.AbstractController;
import com.irdstudio.bsp.console.service.facade.SSubsInfoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class HomePageController extends AbstractController {

    @Autowired
    @Qualifier("sSubsInfoService")
    private SSubsInfoService sSubsInfoService;

    @Autowired
    @Qualifier("PageService")
    private HomePageService homePageService;

    @RequestMapping(value = "/batch/home/pages",method = RequestMethod.POST)
    public @ResponseBody ResponseData<List<HomePageVO>> queryHomePage(SSubsInfoVO sSubsInfoVO){
        List<SSubsInfoVO> outputVo = sSubsInfoService.queryAllOwner(sSubsInfoVO);//查询系统列表
        List<String> list = new LinkedList<>();
        for (SSubsInfoVO item:outputVo
        ) {
			if(!"console".equals(item.getSubsCode())){
                list.add(item.getSubsCode());//将系统列表subsCode字段作为查询参数
            }
        }
        List<HomePageVO> homePageVOList = homePageService.queryAll(list);
        return getResponseData(homePageVOList);
    }

    /**
     * cjw dmp-console首页业务信息查询接口
     * @param page
     * @return
     */
    @RequestMapping(value="/dmpconsole/home/pages", method=RequestMethod.POST)
    public @ResponseBody ResponseData<List<Map>> querydmpconsoleHomePage(SSubsInfoVO sSubsInfoVO){
        List<SSubsInfoVO> outputVo = sSubsInfoService.queryAllOwner(sSubsInfoVO);//查询系统列表
        List<Map> homePageVOMapList = homePageService.querydmpconsoleAll(outputVo);
        return getResponseData(homePageVOMapList);
    }
}
